<template>
	<view class="home">
		<custom-navbar title='产业资讯' :show-back="true" @back="handleBack" />

		<view class="content " :style="{ paddingTop: navBarHeight + 'px' }">
			<view class="p30 policy">
				<view class="f36bc0 mb20" style="line-height: 50rpx;">{{policyDetail.policy_title}}</view>
				<view class="f245c9 mb8">发布：{{policyDetail.issuing_unit}}</view>
				<view class="f245c9 mb28">{{policyDetail.create_time}}</view>
				<mp-html :content="policyDetail.policy_details" />
			</view>
		</view>

	</view>

</template>

<script setup>
	import CustomNavbar from '@/components/custom-navbar.vue'
	import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html'
	import {
		ref,
		onMounted,
		computed
	} from 'vue';
	import {
		onLoad,
		onReachBottom,
		onShow,
		onPullDownRefresh,
	} from '@dcloudio/uni-app'
	import {
		getCurrentInstance
	} from 'vue'
	import {
		PolicyDetail
	} from '@/api/policy'
	// 获取全局cdn方法
	const {
		proxy
	} = getCurrentInstance()
	const cdn = (path) => proxy.$cdn + path
	// 2. 获取系统信息（同步操作放在setup最前面）
	const systemInfo = uni.getSystemInfoSync()

	// 3. 定义响应式数据
	const searchKey = ref('')

	// 4. 计算属性
	const navBarHeight = computed(() => systemInfo.statusBarHeight + 44)

	// 初始化
	// 获取路由参数
	const policy_id = ref('')
	const policyDetail = ref({})
	onMounted(() => {
		// // 获取上个页面传递的参数
		// const eventChannel = getCurrentPages()[getCurrentPages().length - 1].getOpenerEventChannel()

		// // 监听acceptDataFromOpenerPage事件，获取数据
		// eventChannel.on('acceptDataFromOpenerPage', function(data) {
		// 	activityId.value = data.id
		// 	fetchpolicyDetail()
		// })

		// 或者直接从当前页面路由参数获取
		setTimeout(() => {
			const pages = getCurrentPages()
			const currentPage = pages[pages.length - 1]
			const options = currentPage.options
			policy_id.value = options.policy_id

			fetchpolicyDetail()
		}, 100)
	})
	// 获取活动详情
	const fetchpolicyDetail = async () => {

		try {
			if (!policy_id.value) {
				throw new Error('缺少活动ID参数')
			}

			const res = await PolicyDetail(policy_id.value)
			if (res.code === 200) {
				policyDetail.value = res.data
			} else {
				throw new Error(res.message || '获取详情失败')
			}
		} catch (error) {
			console.error('获取活动详情失败:', error)
			uni.showToast({
				title: error.message,
				icon: 'none'
			})
			// 可以在这里返回上一页
			// uni.navigateBack()
		}
	}
	const handleBack = () => {
		uni.navigateBack();
	};
</script>

<style lang="scss" scoped>
	.home {
		width: 100%;
		min-height: 100vh;
		overflow: hidden; // 防止页面整体滚动

		.content {
			padding-top: var(--status-bar-height);
			padding-top: calc(var(--status-bar-height) + 70rpx);
			/* 导航栏高度 */
			height: 100%;
			display: flex;
			flex-direction: column;
			background: #ffffff;
			// flex-direction: column;
			// align-items: center;
			// justify-content: center;



		}
	}
</style>